<?php
include('conexion.php');
$sqlarchi = "SELECT * FROM confinotario where idnotar='1'";
$resultarchi=mysql_query($sqlarchi,$conn);
$rowarchi = mysql_fetch_array($resultarchi);
$ano=date('Y');

$archivo = "3520".$ano.$rowarchi['ruc'].".For";
header('Content-Type: application/force-download');
header('Content-Disposition: attachment; filename='.$archivo);
header('Content-Transfer-Encoding: binary');
header('Content-Length: '.filesize($archivo));
 
include($archivo);

$sql = "SELECT * FROM temp_otg";
$result=mysql_query($sql,$conn);
while($row = mysql_fetch_array($result)) {
	
	      	
		$tipokardex=$row["idtipkar"]; $numeroescritura=$row["numescritura"]; $secuacto=$row["secuencialacto"];  
		 $secuoto=$row["secuencialoto"];  $tipootorgante=$row["tipootorgante"];  $idrenta=$row['idrenta'];
		// tipo de otorgante 
		
		$sqlformu="select * from formulario where idrenta='".$idrenta."'";
	    $resulformu=mysql_query($sqlformu,$conn);
		$rowformu= mysql_fetch_array($resulformu);
		$numformu=$rowformu['numformu'];
		$pagoformu=$rowformu['monto'];
		
		
echo str_pad(intval($tipokardex),1," ",STR_PAD_LEFT)."|".str_pad(intval($numeroescritura),5," ",STR_PAD_LEFT)."|".str_pad($secuacto,5," ",STR_PAD_RIGHT)."|".str_pad($secuencial,5," ",STR_PAD_RIGHT)."|".str_pad($tipootorgante,2," ",STR_PAD_RIGHT)."|".str_pad($numformu,10," ",STR_PAD_RIGHT)."|".str_pad($pagoformu,15," ",STR_PAD_RIGHT)."|".chr(13).chr(10);
		
}
mysql_free_result($result);
mysql_close($conn);

?>